<?php
	$conn=mysql_connect("localhost","root","vertrigo") or die("Không thể kết nối!");
	mysql_select_db("webqtd")or die("không tồn tại CSDL\"webqtd\"!");
	mysql_query("SET NAMES 'utf8'"); //Để hiển thị unicode
	session_start();
	$MaSoTietKiem = $_POST["MaSoTietKiem"];
	$MaKH = $_POST["MaKH"];
	$MaLoaiKyHan = $_POST["MaKyHan"];
	$HinhThucThangNam = $_POST["HinhThucThangNam"];
	if($HinhThucThangNam == "Thang")
		$sqllaisuatgui = "SELECT * FROM laisuatgui WHERE MaLoaiKyHan = $MaLoaiKyHan AND HangThang = 1";
	else
		$sqllaisuatgui = "SELECT * FROM laisuatgui WHERE MaLoaiKyHan = $MaLoaiKyHan AND HangNam = 1";
	$dslaisuatgui = mysql_query($sqllaisuatgui);
	$donglaisuat = mysql_fetch_array($dslaisuatgui);
	$MaLaiSuatGui = $donglaisuat["MaLaiSuatGui"];
	$SoTienGui = $_POST["SoTienGui"];
	$NgayDenHan = $_POST["NgayDenHan"];
	$NgayLanhLai = $_POST["NgayLanhLai"];
	$MaHTLanhLai = $_POST["MaHTLanhLai"];
	$sqlcapnhat = "UPDATE sotietkiem SET MaKH = '$MaKH', MaLoaiKyHan=$MaLoaiKyHan, MaHTLanhLai =$MaHTLanhLai, MaLaiSuatGui = $MaLaiSuatGui, SoTienGui = $SoTienGui, SoDuKyHanTT = $SoTienGui, NgayDenHan = '$NgayDenHan', NgayLanhLai = '$NgayLanhLai' WHERE MaSoTietKiem ='$MaSoTietKiem'";
	$kqcapnhat = mysql_query($sqlcapnhat);
	
	$MaLoaiGiaoDich = $_POST["MaLoaiGiaoDich"];
	$SoButToan = $_POST["SoButToan"];
	$sqlcapnhatloaigiaodich = "UPDATE kekhaigiaodich SET SoTienTaiKhoanNo = $SoTienGui, MaLoaiGiaoDich = $MaLoaiGiaoDich WHERE SoButToan = '$SoButToan'";
	$kqcapnhatgiaodich = mysql_query($sqlcapnhatloaigiaodich);
	
	if($kqcapnhat && $kqcapnhatgiaodich)
	{
		$nhatky = new nhatkybs();
		$nhatky->TenSuKien = "Sửa thông tin sổ tiết kiệm có kỳ hạn";
		$nhatky->MaNguoiDung = $_SESSION["MaND"];
		date_default_timezone_set('Asia/Ho_Chi_Minh');
		$nhatky->ThoiGian = date("Y-m-d H:m:s", time());
		$nhatky->Them();
		header("Location:index.php?do=sotietkiemcokyhan&id=$MaSoTietKiem");
	}
	else 
	{
		header("Location:index.php?do=sotietkiemcokyhan&id=$MaSoTietKiem");
		$_SESSION["LoiSuaTietKiemCo"] = "Lỗi: " . mysql_error();
	}
?>